* bite_graph.do	JEP 	5/10/2015
* Shows bites for industry, two major cities

*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	if c(os)=="Unix" loc master "/home/jperez/AA_Minimum_Wage" 
 else if c(username)=="J16339" loc master "B:\Col_Minimum_Wage"
  else if c(username)=="A15858" loc master "B:\Col_Minimum_Wage"
	else loc master "C:/Users/jorpp/Dropbox (Brown)/Col_Minimum_Wage"
	loc pr=0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'" 
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")
	loc pr=1
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"

glo outdir "`master'/Doc/third_year/tab"

* Define a program to export graphs

cap program drop mex
program define mex
	cap mkdir "`2'/Doc"
	cap mkdir "`2'/Doc/third_year"
	cap mkdir "`2'/Doc/third_year/fig"
	graph export "`2'/Doc/third_year/fig/`1'.eps", replace
	! epstopdf "`2'/Doc/third_year/fig/`1'.eps"
	erase "`2'/Doc/third_year/fig/`1'.eps"
	* project, creates("`master'/Doc/descriptive_figures/density/`1'.pdf")
end	

cap program drop mex3
program define mex3
	cap mkdir "`2'/Doc"
	cap mkdir "`2'/Doc/tosubmit2"
	cap mkdir "`2'/Doc/tosubmit2/fig"
	graph export "`2'/Doc/tosubmit2/fig/`1'.eps", replace
	! epstopdf "`2'/Doc/tosubmit2/fig/`1'.eps"
	erase "`2'/Doc/tosubmit2/fig/`1'.eps"
	graph export "`2'/Doc/tosubmit2/fig/`1'.pdf", replace
	graph export "`2'/Doc/tosubmit2/fig/`1'.png", replace
	graph export "`2'/Doc/tosubmit2/ILR-Figs/Fig3_`1'.png", replace
	* project, creates("`master'/Doc/descriptive_figures/density/`1'.pdf")
end	

* Draw graphs for formal sector
use "`master'/Data/Source/ocupados_mw.dta", clear
mysample rif4sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) formal exind(13,29,42)

mw_measures rif4sample , stub(rif4)
keep if rif4sample
keep if time==tq(1998q4)
bys ccode cactividad_empresa: keep if _n==1

gen cactividad_empresa_eng=cactividad_empresa
label define cactividad_empresa_eng 13 "Agriculture"
label define cactividad_empresa_eng 29 "Mining" , add
label define cactividad_empresa_eng 39 "Manufacturing" , add
label define cactividad_empresa_eng 42 "Utilities" , add
label define cactividad_empresa_eng 50 "Construction" , add
label define cactividad_empresa_eng 63 "Trade" , add
label define cactividad_empresa_eng 72 "Transport" , add
label define cactividad_empresa_eng 83 "Financial" , add
label define cactividad_empresa_eng 96 "Services" , add
                                      
la val cactividad_empresa_eng cactividad_empresa_eng
la var cactividad_empresa_eng "Industry"

replace ciudad="BOGOTA" if ccode==2
replace ciudad="MEDELLIN" if ccode==6
replace ciudad=lower(ciudad)
replace ciudad=proper(ciudad)

graph drop _all
* Choose samples - get them from the estimates

set scheme s2color

foreach c in Bogota Pasto {
	preserve
	keep if ciudad=="`c'"
	graph bar bite_rif4_ind, over(cactividad_empresa_eng, label(angle(90))) ytitle("Fraction affected (%)") subtitle(`c' - Formal) name(`c'f) legend(off) graphregion(color(white))
	restore
}

* Draw graphs for informal sector
use "`master'/Data/Source/ocupados_mw.dta", clear
mysample rif10sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal exind(13,29,42)

mw_measures rif10sample , stub(rif10)
keep if rif10sample
keep if time==tq(1998q4)
bys ccode cactividad_empresa: keep if _n==1

gen cactividad_empresa_eng=cactividad_empresa
label define cactividad_empresa_eng 13 "Agriculture"
label define cactividad_empresa_eng 29 "Mining" , add
label define cactividad_empresa_eng 39 "Manufacturing" , add
label define cactividad_empresa_eng 42 "Utilities" , add
label define cactividad_empresa_eng 50 "Construction" , add
label define cactividad_empresa_eng 63 "Trade" , add
label define cactividad_empresa_eng 72 "Transport" , add
label define cactividad_empresa_eng 83 "Financial" , add
label define cactividad_empresa_eng 96 "Services" , add
                                      
la val cactividad_empresa_eng cactividad_empresa_eng
la var cactividad_empresa_eng "Industry"

replace ciudad="BOGOTA" if ccode==2
replace ciudad="MEDELLIN" if ccode==6
replace ciudad=lower(ciudad)
replace ciudad=proper(ciudad)

set scheme s2color

foreach c in Bogota Pasto {
	preserve
	keep if ciudad=="`c'"

	graph bar bite_rif10_ind, over(cactividad_empresa_eng, label(angle(90))) ytitle("Fraction affected (%)") subtitle(`c' - Informal) name(`c'i) legend(off) graphregion(color(white))
	restore
}

* Combine

graph combine Bogotaf Pastof Bogotai Pastoi, ycommon rows(2) graphregion(color(white))
mex bitegraph "`master'"
mex3 bitegraph "`master'"

* if `pr' project, creates("`master'/Doc/third_year/bitegraph.pdf")
if `pr' project, creates("`master'/Doc/tosubmit2/fig/bitegraph.pdf")


